﻿using System;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using vtech_frameWorks.DAO;
using vtech_frameWorks.Exceptions;

namespace vtech_system.Department
{
    public class ClsDepartmentDAO
    {
        #region "Get All"
        /****** 
        * =============================================
        * Author:		<chaunn>
        * Create date: <10.03.2011>
        * Good
        * Description:	Lấy tất cả Phòng ban
        * =============================================
        * ******/
        /// <summary>
        /// Lấy tất cả Phòng ban
        /// </summary>
        /// <param name="sqlTransaction"></param>
        /// <returns></returns>
        public static DataTable GetAll()
        {
            return GetAll(null);
        }

        /****** 
        * =============================================
        * Author:		<chaunn>
        * Create date: <10.03.2011>
        * Good
        * Description:	Lấy tất cả Phòng ban
        * =============================================
        * ******/
        /// <summary>
        /// Lấy tất cả phòng ban
        /// </summary>
        /// <param name="sqlTransaction"></param>
        /// <returns></returns>
        public static DataTable GetAll(SqlTransaction sqlTransaction)
        {
            try
            {
                return ClsBaseDbAccessDAO.ExecuteSqlDataAdapter(sqlTransaction, "spGetDepartment").Tables[0];
            }
            catch (Exception ex)
            {
                ClsInformation.Error(ex.Message);
                return null;
            }
        }
        #endregion

        #region "Insert"
        /****** 
        * =============================================
        * Author:		<chaunn>
        * Create date: <10.03.2011>
        * Good
        * Description:	Thêm mới phòng ban
        * =============================================
        * ******/
        /// <summary>
        /// Thêm mới phòng ban
        /// </summary>
        /// <param name="dRow"></param>
        public static void Insert(DataRow dRow)
        {
            Insert(null, dRow);
        }

        /****** 
        * =============================================
        * Author:		<chaunn>
        * Create date: <10.03.2011>
        * Good
        * Description:	Thêm mới phòng ban
        * =============================================
        * ******/
        /// <summary>
        /// Thêm mới phòng ban
        /// </summary>
        /// <param name="sqlTran"></param>
        /// <param name="dRow"></param>
        public static void Insert(SqlTransaction sqlTran, DataRow dRow)
        {
            try
            {
                SqlParameter[] paramArray = new SqlParameter[]
                {
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@DepartmentID", SqlDbType.UniqueIdentifier, 1, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@DepartmentCode", SqlDbType.NVarChar, 20, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@DepartmentName", SqlDbType.NVarChar, 255, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@BranchID", SqlDbType.UniqueIdentifier, 1, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@Description", SqlDbType.NVarChar, 255, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@Inactive", SqlDbType.Bit, 1, ParameterDirection.Input)
                };
                ClsBaseDbAccessDAO.SetParameterValues(paramArray, dRow);
                ClsBaseDbAccessDAO.ExecuteProcedure(sqlTran, "spAddDepartment", paramArray);
            }
            catch (Exception ex)
            {
                ClsInformation.Error(ex.Message);
            }
        }
        #endregion

        #region "Edit"
        /****** 
        * =============================================
        * Author:		<chaunn>
        * Create date: <10.03.2011>
        * Good
        * Description:	Edit phòng ban
        * =============================================
        * ******/
        /// <summary>
        /// Edit Phòng ban
        /// </summary>
        /// <param name="dRow"></param>
        public static void Edit(DataRow dRow)
        {
            Edit(null, dRow);
        }

        /****** 
        * =============================================
        * Author:		<chaunn>
        * Create date: <10.03.2011>
        * Good
        * Description:	Edit phòng ban
        * =============================================
        * ******/
        /// <summary>
        /// Edit phòng ban
        /// </summary>
        /// <param name="sqlTran"></param>
        /// <param name="dRow"></param>
        public static void Edit(SqlTransaction sqlTran, DataRow dRow)
        {
            try
            {
                SqlParameter[] paramArray = new SqlParameter[]
                {
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@DepartmentID", SqlDbType.UniqueIdentifier, 1, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@DepartmentCode", SqlDbType.NVarChar, 20, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@DepartmentName", SqlDbType.NVarChar, 255, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@BranchID", SqlDbType.UniqueIdentifier, 1, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@Description", SqlDbType.NVarChar, 255, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@Inactive", SqlDbType.Bit, 1, ParameterDirection.Input)
                };
                ClsBaseDbAccessDAO.SetParameterValues(paramArray, dRow);
                ClsBaseDbAccessDAO.ExecuteProcedure(sqlTran, "spEditDepartment", paramArray);
            }
            catch (Exception ex)
            {
                ClsInformation.Information(ex.Message);
            }
        }
        #endregion

        #region "Delete"
        /****** 
        * =============================================
        * Author:		<chaunn>
        * Create date: <10.03.2011>
        * Good
        * Description:	Xóa phong ban
        * =============================================
        * ******/
        /// <summary>
        /// Xóa phong ban
        /// </summary>
        /// <param name="dataRow"></param>
        public static void Delete(DataRow dataRow)
        {
            Delete(null, dataRow);
        }

        /****** 
        * =============================================
        * Author:		<chaunn>
        * Create date: <10.03.2011>
        * Good
        * Description:	Xóa phong ban
        * =============================================
        * ******/
        /// <summary>
        /// Xóa user
        /// </summary>
        /// <param name="sqlTransaction"></param>
        /// <param name="dataRow"></param>
        public static void Delete(SqlTransaction sqlTransaction, DataRow dataRow)
        {
            //string deleteString = "spDeleteDepartment";
            try
            {
                SqlParameter[] paramArray = new SqlParameter[]
                {
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@DepartmentID", SqlDbType.UniqueIdentifier, 0, ParameterDirection.Input),
                };
                ClsBaseDbAccessDAO.SetParameterValues(paramArray, dataRow);

                ClsBaseDbAccessDAO.ExecuteNonQuery(sqlTransaction, "DELETE FROM   [tblDepartment] WHERE  [DepartmentID] = @DepartmentID", paramArray);
            }
            catch (Exception ex)
            {
                ClsInformation.Information(ex.Message);
            }
        }
        #endregion
    }
}
